package org.catdroid.englishformusicians;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.speech.RecognizerIntent;

public class GoogleVoiceUtil {

	public static final int VOICE_RECOGNITION_REQUEST_CODE = 42;

	public static boolean isGoogleVoiceEnabled(Context c) {
		PackageManager pm = c.getPackageManager();
		List<ResolveInfo> activities = pm.queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
		return activities.size() != 0;
	}

	public static void launchGoogleVoice(Activity a, String s) {
		Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
		intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
		intent.putExtra(RecognizerIntent.EXTRA_PROMPT, s);
		a.startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
	}
}
